package com.cheng.admin.controller;


import cn.dev33.satoken.annotation.SaCheckRole;
import com.cheng.admin.model.Delivery;
import com.cheng.admin.service.DeliveryService;
import com.cheng.common.domain.BaseSearchVO;
import com.cheng.common.domain.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 快递 前端控制器
 * </p>
 *
 * @author 起凡
 * @since 2022-01-17
 */
@RestController
@RequestMapping("/delivery")
public class DeliveryController {
    @Autowired
    DeliveryService deliveryService;

    @GetMapping("get")
    public R<Delivery> get(@RequestParam Long id) {
        return R.ok(deliveryService.getById(id));
    }

    @GetMapping("list")
    public R<PageInfo<Delivery>> list(BaseSearchVO searchVO) {
        PageHelper.startPage(searchVO.getPageNum(), searchVO.getPageSize());
        PageInfo<Delivery> deliveryPageInfo = new PageInfo<>(deliveryService.list());
        return R.ok(deliveryPageInfo);
    }


    @SaCheckRole("admin")
    @PostMapping("save")
    public R<Boolean> save(@RequestBody @Validated Delivery delivery) {
        deliveryService.saveOrUpdate(delivery);
        return R.ok(true);
    }

    @SaCheckRole("admin")
    @GetMapping("delete")
    public R<Boolean> delete(@RequestParam Long id) {
        deliveryService.removeById(id);
        return R.ok(true);
    }
}

